<!--   
Persistent Digital Archives and Library System (PeDALS) 
(c) 2008 - All Rights Reserved
//-->
<?php
include ("includes\config.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="description" content="Persistent Digital Archives and Library System" />
<title>PeDALS Web Administration</title>
<link rel="shortcut icon" href="images/favicon.ico" />
<link href="includes/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php include 'includes\header.php'; ?>
<div id="breadcrumb-container">
  <div id="breadcrumb"><a href="index.php" title=Home page">Home</a> / Provenances</div>
  <div id="breadcrumb-side"><form name="search" action="search.php"><input type="text" name="q" width="50"/><input type="submit" value="Go" /></form><a href="advSearch.php" title="Advanced Search" alt="Advanced Search">Advanced Search</a>
  </div>
  <div class="clear"></div>
</div>
<!-- 
  CONTENT
  -->
<div id="content-container">
  <!-- 
	SIDE COLUMN
	-->
  <div id="content-side">
    <ul class="link-list-vertical">
      <li><a href="provNew.php" title="Add a provenance to PeDALS.">Add Provenance</a></li>
    </ul>
  </div>
  <!-- 
	MAIN COLUMN
	-->
  <div id="content"><a name="maincontent" id="maincontent"></a>
    <h1>Provenances</h1>
 
        <table class="table" border="1" cellspacing="0" summary="Table listing all the provenances set up in PeDALS">
      <thead>
        <tr>
          <th scope="col" abbr="name">Name</th>
          <th scope="col">Type</th>
          <th scope="col">Statistics</th>
          <th scope="col">View</th>
          <th scope="col">Edit</th>
        </tr>
      </thead>
      <tbody>
<?php
	$sql = "SELECT     ProvenanceId, ProvenanceName AS Name, 'provNotVariant' as Type
			FROM         dbo.Provenance
			UNION
			SELECT     TOP (100) PERCENT ProvenanceId, ProvenanceVariantName AS Name,(SELECT QualifierType FROM Qualifier WHERE QualifierId =  dbo.ProvenanceVariant.QualifierId) as Type
			FROM         dbo.ProvenanceVariant
			ORDER BY Name";
			
	$getData=sqlsrv_query( $conn, $sql);

	/* Create the statement. 
	$getData = sqlsrv_prepare( $conn, $tsql);*/
	if( $getData === false ) {
		 echo "Error in preparing statement.\n";
		 die( print_r( sqlsrv_errors(), true));
	}

$rowCount = 0;

while($row = sqlsrv_fetch_array($getData, SQLSRV_FETCH_ASSOC)){	
	echo provNameOpen($row['Name'],$row['ProvenanceId'],$row['Type']);
	$rowCount++;
	}

	
	if( $rowCount == 0 ) { 
	    echo "<h4>There are no provenances set up yet.</h4>"; 
	}
    sqlsrv_free_stmt( $getData );	
	sqlsrv_close( $conn);

function provNameOpen($namepp,$idpp,$type){
	/*display Variant and provenance 4-14-2010*/
	if($type == 'provNotVariant'){//format proveANCE
		$t = '
		<tr>
			<td align="left" valign="top" colspan="2" id="show_'.$idpp.'">
				<a title="'.$namepp.'" alt="'.$namepp.'" href="provDetail.php?prov='.$idpp.'">
					'.$namepp.'
					<a name="show_'.$idpp.'">
				</a>
			</td>

			<td align="center" valign="top">
				<a title="Statistics" href="statistics.php?prov='.$idpp.'">
					<img src="images/view.png" border="0" alt="Statistics">
				</a>
			</td>
			<td align="center" valign="top">
				<a title="View" href="provDetail.php?prov='.$idpp.'">
					<img src="images/view.png" border="0" alt="View"/>
				</a>
			</td>
			<td align="center" valign="top">
				<a title="Edit" href="provEdit.php?prov='.$idpp.'">
					<img src="images/edit.png" border="0" alt="Edit"/>
				</a>
			</td>
		</tr>';
		}
	else{//format variant
		$t = '
		<tr>
			<td align="left" valign="top">
				<i><a title="'.$namepp.'" alt="'.$namepp.'" href="provDetail.php?prov='.$idpp.'" style="color:#F00;">
					'.$namepp.'
				</a></i>
			</td>
			<td align="center" valign="top">
			<a href="#show_'.$idpp.'" onclick="ala(\'show_'.$idpp.'\')">'.$type.'</a>
			</td>
			<td align="center" valign="top">
				<a title="Statistics" href="statistics.php?prov='.$idpp.'">
					<img src="images/view.png" border="0" alt="Statistics">
				</a>
			</td>
			<td align="center" valign="top">
				<a title="View" href="provDetail.php?prov='.$idpp.'">
					<img src="images/view.png" border="0" alt="View"/>
				</a>
			</td>
			<td align="center" valign="top">
				<a title="Edit" href="provEdit.php?prov='.$idpp.'">
					<img src="images/edit.png" border="0" alt="Edit"/>
				</a>
			</td>
		</tr>';
		}	
	
	return $t;
	}
?>
      </tbody>
    </table>


<?php include 'includes\footer.php'; ?>
  </div>
</div>

<script type="text/javascript">

function ala(id){
	var dd = document.getElementsByTagName('td');   
    for(var i=0;i<dd.length;i++){
		if(document.getElementsByTagName('td').item(i).id.length > 0){
			document.getElementsByTagName('td').item(i).style.backgroundColor = '#FFFFFF';
			}		
		}    
  
	document.getElementById(id).style.backgroundColor = "#ffcc99";
    var code = "document.getElementById('"+id+"').style.backgroundColor = '#FFFFFF'";
    setTimeout(code,10000);
}

</script>
</body>
</html>